/**
 * @param {number} n
 * @return {number}
 */
var numDupDigitsAtMostN = function (n) {
  if (n < 11) return 0
  let str, left, right
  ;(set = new Set()), (count = 0)
  for (let i = 11; i <= n; i++) {
    str = '' + i
    ;(left = 0), (right = str.length - 1)
    while (left < right) {
      if (set.has(str[left])) {
        count++
        set.clear()
        break
      } else {
        set.add(str[left])
        left++
      }
      if (set.has(str[left])) {
        count++
        set.clear()
        break
      } else {
        set.add(str[right])
        right--
      }
    }
    set.clear()
  }
  return count
}

numDupDigitsAtMostN(20)
